<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>修改用户</title>
    <link rel="stylesheet" type="text/css" href="layui/css/layui.css">
    <script src="layui/layui.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div class="layui-container" style="margin-top: 20px">
    <div class="layui-row">
        <div class="layui-col-md6 layui-col-md-offset3">
            <form class="layui-form"> <!-- 提示：如果你不想用form，你可以换成div等任何一个普通元素 -->
                <input type="hidden" id="gid" th:value="${user.uid}">
                <div class="layui-form-item">
                    <label class="layui-form-label" for="name">姓名</label>
                    <div class="layui-input-block">
                        <input type="text" id="name" name="name" placeholder="真实姓名" class="layui-input" th:value="${user.name == null ? '' : user.name}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" for="licensePlate">车牌号</label>
                    <div class="layui-input-block">
                        <input type="text" id="licensePlate" name="licensePlate" placeholder="车牌号" class="layui-input" maxlength="7" th:value="${car ?.licensePlate}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" for="idNumber">身份证号</label>
                    <div class="layui-input-block">
                        <input type="text" id="idNumber" name="idNumber" placeholder="idNumber" class="layui-input" maxlength="18" th:value="${user.idNumber == null ? '' : user.idNumber}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" for="phoneNumber">手机号</label>
                    <div class="layui-input-block">
                        <input type="text" id="phoneNumber" name="phoneNumber" placeholder="手机号" maxlength="11" class="layui-input" th:value="${user.phoneNumber == null ? '':user.phoneNumber}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" for="email">电子邮箱</label>
                    <div class="layui-input-block">
                        <input type="text" id="email" name="email" placeholder="电子邮箱" class="layui-input" th:value="${user.email==null?'':user.email}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" for="wallet">钱包</label>
                    <div class="layui-input-block">
                        <input type="text" disabled id="wallet" name="wallet" placeholder="钱包" class="layui-input" th:value="${user.wallet}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="editUser">修改</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>

            </form>
        </div>
    </div>
</div>
<script th:inline="javascript">
    layui.use(['layer', 'form', 'laydate'], function () {
        var $ = layui.jquery;
        var form = layui.form;

        form.on('submit(editUser)', function (obj) {
            //AJAX请求，用到了thymeleaf内敛脚本
            obj.field.uid=[[${user.uid}]];
            console.log("===========",obj)
            $.post("updateUser", obj.field, function (d) {
                console.log("d=" + d);
                if (d === 1) {
                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(index); //再执行关闭
                    alert("修改成功")
                    // layer.msg(d);
                } else {
                    //关闭弹出层
                    // layer.getFrameIndex(windowName) - 获取特定iframe层的索引
                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(index); //再执行关闭
                }
            }, "json");
            //取消form提交的默认submit行为
            return false;
        });
    })
</script>
</body>
</html>